#include "suffixindex.h"

void suffixindex_main() {
  // comparison_counter = 0;
  // hash_counter = 0;

  SuffixIndex<int32, char> si;
  // si.RandomData(100000);
  si.LoadData("foo");
  // si.LoadData("stringmatch.h");
  // si.LoadIndex("index");
  si.BuildIndex();
  cout << "built index" << endl;
  cout << "comparison counter " << comparison_counter << endl;
  cout << "hash counter " << hash_counter << endl;
  cout << "identical_character_counter " << identical_character_counter << endl;
  cout << "bisection_comparison_counter " << bisection_comparison_counter << endl;
  cout << "comarisons avoided by bisection " 
       << (identical_character_counter - direct_comparison_counter) << endl;
  // return;
  si.StoreIndex("index");
  string s;
  while (cin >> s) {
    int32 * match_begin;
    int32 * match_end;
    si.Search((char *)s.c_str(), s.length(), &match_begin, &match_end);
    cout << (match_end - match_begin) << " matches found: "; 
    for (int32 * run = match_begin; run!=match_end; run++) {
      cout << *run << " ";
    }
    cout << endl;
  }
}

int main() {
  suffixindex_main();
  return 0;
}
